﻿using System.Collections.Generic;
using System.Threading.Tasks;
using ZSoftInstagram.DataAccess.Abstractions;
using ZSoftInstagram.Domain;
using ZSoftInstagram.Domain.User;
using ZSoftInstagram.Services.Abstraction;
using ZSoftInstagram.UI.ViewModels;
using System.Linq;
using System.Data.Entity;

namespace ZSoftInstagram.Services
{
    /// <summary>
    /// Bussiness logic for user entites
    /// </summary>
    public class UserService: IUserService
    {

        private IRepository<ApplicationUser> _repository;

        public UserService(IRepository<ApplicationUser> repository)
        {
            this._repository = repository;
        }

        public IRepository<ApplicationUser> Repository
        {
            get
            {
                return this._repository;
            }
        }


        public Task<List<UserLikesModel>> GetUserLikesAsync(int currentUserId)
        {
            return this._repository.GetTypeRepository<Like>()
                                        .Where(l => l.UserId == currentUserId)
                                            .Select(l => new UserLikesModel()
                                            {
                                                Id = l.Id,
                                                Pin = new PinViewModel()
                                                {
                                                    Address = new AddressViewModel()
                                                    {
                                                        Path = l.ImagePin.Address.Path, AddressType = l.ImagePin.Address.AddresType
                                                    },
                                                    Id = l.ImagePin.Id
                                                }
                                            }).ToListAsync();

        }
    }
}
